# Create your views here.
from django.http import HttpResponse
from django.contrib.auth.models import UserManager, User


def hello_view(request):
    return HttpResponse("Hello World!!!")

def setup_admin(request):
    users = User.objects.filter(is_active=True, is_superuser=True).all()
    
    if len(users) == 0:
        user = User.objects.create_superuser("admin","piratepolitics@gmail.com","password")
        resp = "Superuser with name 'admin' and password 'password' created." 
        return HttpResponse(resp)
    
    elif len(users) > 0:
        number = len(users)
        first = users[0]
        resp = "%s superuser(s) already exist(s), including user with username '%s'" \
             % (number, first.username)
        return HttpResponse(resp)

    else:
        raise Exception("This should not be reached.")

